//
//  AppDelegate.m
//  beautifulHome
//
//  Created by lanou on 15/12/17.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "AppDelegate.h"
#import "ProfessorViewController.h"

#import <SystemConfiguration/SystemConfiguration.h>
#import "Reachability.h"

#import "OneDatBase.h"


@interface AppDelegate ()<UITabBarControllerDelegate>

@property (nonatomic,strong)UIAlertView *unavailAlert;


@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    
   
    
    BrowseTableViewController *browseTVC = [[BrowseTableViewController alloc] init];

   browseTVC.tabBarItem.image = [[UIImage imageNamed:@"hd_ictab_homepage_selected"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
    
    SecondViewController *secondVC = [[SecondViewController alloc] init];
    
    secondVC.tabBarItem.image = [[UIImage imageNamed:@"a"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
    
    ProfessorViewController *professorVC = [[ProfessorViewController alloc] init];
    
    MyTableViewController *myTVC = [[MyTableViewController alloc] init];
    
    UINavigationController *myNC = [[UINavigationController alloc] initWithRootViewController:myTVC];
    
    UINavigationController *browseNC = [[UINavigationController alloc] initWithRootViewController:browseTVC];
    
    
    UINavigationController *secondNC = [[UINavigationController alloc] initWithRootViewController:secondVC];
    
    
    UINavigationController *professorNC = [[UINavigationController alloc] initWithRootViewController:professorVC];
    
    
    
    InfoTableViewController *infoTVC = [[InfoTableViewController alloc] init];
    UINavigationController *inNC = [[UINavigationController alloc] initWithRootViewController:infoTVC];
    
    // 1. 创建
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    
    // 2. 给标签视图控制器设置子视图控制器
    // 设置属性
    // viewControllers 存放子视图
    tabBarController.viewControllers = @[browseNC,secondNC,professorNC,inNC,myNC];
    
    browseNC.title = @"浏览";
    secondNC.title = @"灵感";
    professorNC.title = @"专家";
    myNC.title = @"我的";
    inNC.title = @"商城";
    
    // 标签条 tabBar
    tabBarController.tabBar.barTintColor = [UIColor whiteColor]; // 标签条颜色
    
    // tintColor 影响的是 tabBar上字体颜色 和 图片渲染颜色，系统默认为蓝色
    tabBarController.tabBar.tintColor = [UIColor orangeColor];
    
    // 被选中的标签
    tabBarController.selectedIndex = 0;
    
    // 代理 用于检测用户操作
    tabBarController.delegate = self;
    
    self.window.rootViewController = tabBarController;

    Reachability *r= [Reachability reachabilityForInternetConnection];
    if ([r currentReachabilityStatus] == NotReachable) {
        self.unavailAlert = [[UIAlertView alloc] initWithTitle:@"提示"message:@"现在没有网了" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"去设置", nil];
       
        
        [self.unavailAlert show];
        
    }else{
        
        self.unavailAlert = [[UIAlertView alloc] initWithTitle:@"Warning"message:@"现在wifi在线" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
        [self.unavailAlert show];
        
        //加一个定时器让提示框消失
        NSTimer *timer;
        
        timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(doTime) userInfo:nil repeats:NO];
    }

    //创建数据库的表
    [[OneDatBase shareSqliteManger]createSqliteTableWithName:@"ViewList"];
    
    
    
    return YES;
}

-(void)doTime{
    [self.unavailAlert dismissWithClickedButtonIndex:0 animated:NO];

}












- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
